<template>
  <el-row :gutter="15">
    <el-col :span="24">
      <el-card class="search-form">
        <el-form ref="searchForm" class="el-form-col" :model="search">
          <el-row :gutter="15">
            <el-col :lg="4" :md="6">
              <el-form-item prop="orderNo" style="position: relative">
                <el-input v-model="search.orderNo" type="textarea" :rows="4" clearable placeholder="关联订单号  (支持多单查询，单号之间用英文逗号分隔)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="outWarehouseNo" style="position: relative">
                <el-input v-model="search.outWarehouseNo" type="textarea" :rows="4" clearable placeholder="出库单号  (支持多单查询，单号之间用英文逗号分隔)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="consigneName">
                <el-input v-model="search.consigneName" placeholder="客户姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-lg-only hidden-xl-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="8">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button type="primary" plain @click="isOpen = !isOpen">{{ isOpen ? '收起' : '展开' }}</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button @click="resetFields" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="consignePhone">
                <el-input v-model="search.consignePhone" placeholder="客户电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="owner">
                <el-input v-model="search.owner" placeholder="商家名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-md-only hidden-sm-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="8">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button type="primary" plain @click="isOpen = !isOpen">{{ isOpen ? '收起' : '展开' }}</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button @click="resetFields" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="outWarehouseName">
                <el-select v-model="search.outWarehouseName" placeholder="出库仓">
                  <el-option v-for="item in warehouseIdArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item  prop="confirmUserName">
                <el-input v-model="search.confirmUserName" placeholder="操作人"></el-input>
              </el-form-item>
            </el-col>

            <el-col :lg="4" :md="6">
              <el-form-item prop="orderType">
                <el-select v-model="search.orderType" placeholder="关联订单类型">
                  <el-option v-for="item in followTypeArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="outTypeCode">
                <el-select v-model="search.outTypeCode" placeholder="仓储类型">
                  <el-option v-for="item in tempArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <div v-show="isOpen">
              <el-row :gutter="15">
                <el-col :lg="4" :md="6">
                  <el-form-item  prop="confirmStartTime">
                    <el-date-picker type="date"
                                    placeholder="出库开始时间"
                                    v-model="search.confirmStartTime"
                                    value-format="yyyy-MM-dd"
                                    style="width: 100%;"></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :lg="4" :md="6">
                  <el-form-item prop="confirmEndTime">
                    <el-date-picker type="date"
                                    placeholder="出库结束时间"
                                    v-model="search.confirmEndTime"
                                    value-format="yyyy-MM-dd"
                                    :picker-options="{disabledDate}"
                                    style="width: 100%;">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-row>

        </el-form>
      </el-card>
    </el-col>
    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-warehouse-order/outWarehose/findOutWarehouseRecordList"
        :columns="columns"
      >
        <template slot="preColumn">
          <el-table-column prop="orderNo" fixed="left" width="170px" align="center" label="关联订单">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="show1(scope.row)">{{ scope.row.orderNo }}</a>
            </template>
          </el-table-column>
          <el-table-column prop="outWarehouseNo" fixed="left" width="170px" align="center" label="出库单号">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="show(scope.row)">{{ scope.row.outWarehouseNo }}</a>
            </template>
          </el-table-column>
        </template>
        <template slot="column">
          <el-table-column fixed="right" width="100px" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="show(scope.row)"
              >
                详情
              </el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
  </el-row>
</template>

<script>
import {filterDataBaseDictionary, unixTimestampFilter, filterSecond} from '@/filters'
import {getAllWarehouse, getSubDictListOfParentCode, getCargoSourceType} from '@/utils/selectOptions'
import moment from 'moment'
import {copy} from '@/utils'

export default {
  name: 'warehouseRecordEnterWarehouse',
  filters: {
    filterDataBaseDictionary,
    unixTimestampFilter,
    filterSecond
  },
  data() {
    let columns = [
      {
        label: '客户姓名',
        data: 'consigneName'
      },
      {
        label: '客户电话',
        data: 'consignePhone'
      },
      {
        label: '关联订单类型',
        width: '100px',
        data: 'orderType',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '出库仓',
        data: 'warehouse',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '仓储类型',
        data: 'outTypeCode',
        width: '100px',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '商家名称',
        data: 'cargoOwner'
      },
      {
        label: '总体积(m³)',
        width: '82px',
        data: 'totalVolume'
      },
      {
        label: '总包件(件)',
        width: '82px',
        data: 'totalPackage'
      },
      {
        label: '总重量(kg)',
        width: '82px',
        data: 'totalWeight'
      },
      {
        label: '操作人',
        data: 'confirmUserName'
      },
      {
        label: '出库时间',
        width: '134px',
        data: 'confirmDate',
        render(data, full) {
          return unixTimestampFilter(data, 'YYYY-MM-DD HH:mm')
        }
      }
    ]
    return {
      warehouseIdArr: [],
      searchLoading: false,
      isOpen: false,
      search: {
        orderNo: '',
        outWarehouseNo: '',
        consigneName: '',
        consignePhone: '',
        owner: '',
        orderType: '',
        outTypeCode: '',
        outWarehouseName: '',
        confirmUserName: '',
        confirmStartTime: '',
        confirmEndTime: ''
      },
      columns,
      followTypeArr: [],
      tempArr: []
    }
  },
  created() {
    getAllWarehouse().then(arr => {
      this.warehouseIdArr = arr
    })
    // 关联订单类型：通用字典接口查
    getSubDictListOfParentCode('STORAGEORDERTYPE').then(arr => {
      if (Array.isArray(arr)) {
        this.followTypeArr = arr
      }
    })
    getCargoSourceType().then(arr => {
      this.tempArr = arr
    })
  },
  methods: {
    disabledDate(time) {
      return time.getTime() < moment(this.search.confirmStartTime).format('x')
    },
    searchFunc() {
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let data = copy(this.search)
        this.searchLoading = true
        basicTable.search(data).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    resetFields() {
      const searchForm = this.$refs.searchForm
      if (searchForm) {
        searchForm.resetFields()
      }
    },
    // 跳转详情
    show(data) {
      this.$router.push({path: '/ss-oms/warehouse/record/OutShow/' + data.id, query: {state: 4}})
    }
  }
}
</script>

<style scoped>

</style>
